(mpistuff)= # MPI The `slepc` and `petsc` parts of `quimb` (`eigh(..., k=..., method='slepc')`, `svds(..., method='slepc')`, `expm(..., method='slepc')` etc.), as well as often being faster than `scipy`, perform the calculations using MPI and are thus suited to clusters with many nodes. These generally perform best when run on multiple, single-threaded MPI processes, whereas `numpy` and `scipy` need single-process multi-threaded exectution to parallize (via BLAS). By default, `quimb` thus switches between standard execution and a cached pool of MPI processes when required. It can also run more explicitly under MPI as descibed in {ref}`modes-of-execution`. If running in a distributed cluster it is also best not to pass full operators to these functions (which will be pickled then transferred), rather it is best to leave the operator unconstructed, whith each worker constructing only the rows it needs. 1. The first aspect is handled by the {class}`~quimb.Lazy` object, which is essentially `functools.partial` with a `.shape` attribute that must be supplied. 2. The second aspect (only constructing the right rows) is achieved whenever a function takes a `ownership` argument specifying the slice of rows to construct. Any operators based on {func}`~quimb.kron` and {func}`~quimb.ikron` such as the built-in Hamiltonians can do this. See the {ref}`examples` for a demonstration of this. (modes-of-execution)= ## Modes of execution - Normal, "dynamic MPI mode": main process is not MPI, can run many OMP threads, dynamically spawns a cached mpi pool of processes which are not multithreaded (for efficiency) to do MPI things. Works for interactive sessions and allows OMP parallelism followed by MPI parallelism. Might not work well in a multi-node setting. - `quimb-mpi-python`, "mpi4py.futures mode": all processes are MPI, are spawned at start and have single OMP thread. Workers are split off at startup and only master runs the script, passing args and results using pickle to workers. This is achieved using ` python -m mpi4py.futures